import Enum from '@/vng/enum'
import go from 'gojs'

const props = [
  {
    key: 'loc',
    title: '坐标',
    type: Enum.Field.POINT
  },
  {
    key: 'width',
    title: '宽度',
    type: Enum.Field.INT
  },
  {
    key: 'height',
    title: '高度',
    type: Enum.Field.INT
  },
  {
    key: 'strokeWidth',
    title: '线宽',
    type: Enum.Field.FLOAT,
    args: {
      precision: 1
    }
  },
  {
    key: 'stroke',
    title: '颜色',
    type: Enum.Field.COLOR
  },
  // {
  //   key: 'fillColor',
  //   title: '填充颜色',
  //   type: Enum.Field.COLOR
  // },
  {
    key: 'fontColor',
    title: '文字颜色',
    type: Enum.Field.COLOR
  },
  {
    key: 'fontSize',
    title: '文字大小',
    type: Enum.Field.INT
  }
]

function BuildItem(item, args) {
  const _item = { ...item }
  _item.data = args
  return _item
}

const factory = {
  loc: function(item, datas, core) {
    const { loc } = datas
    const _pt = go.Point.parse(loc)
    if (!_pt) {
      return BuildItem(item, { x: 0, y: 0, z: 0 })
    } else {
      return BuildItem(item, { x: _pt.x, y: _pt.y * -1, z: 0 })
    }
  }
}

export default { props, factory }
